<?php

namespace App\Http\ViewComposers;

use App\Models\Food;
use Illuminate\View\View;

class ShowComposer
{
    protected $foods;

    public function __construct(Food $foods)
    {
        // 依赖关系由服务容器自动解析...
        $this->foods = $foods::all();
    }

    /**
     * 将数据绑定到视图。
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        $view->with('list', array('name'=>'test','avatar'=>'/path/to/test.jpg'));
    }
}